package com.medical.view.admin.user;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.medical.model.admin.AdminDbOperation;
import com.medical.view.wicket.sort.MedSortableDataProvider;

 
 

public class UserProvider extends MedSortableDataProvider {

	class SortableDataProviderComparator implements Comparator< Object>, Serializable {
		public int compare(final Object o1, final Object o2) {
			PropertyModel<Comparable> model1 = new PropertyModel<Comparable>(o1, getSort().getProperty());
			PropertyModel<Comparable> model2 = new PropertyModel<Comparable>(o2, getSort().getProperty());
//
			int result = model1.getObject().compareTo(model2.getObject());
//
			if (!getSort().isAscending()) {
				result = -result;
			}

			return result;
		}

	}

//	private List list = new ArrayList<Contact>();
	private SortableDataProviderComparator comparator = new SortableDataProviderComparator();

	public UserProvider() {
//		// The default sorting
//		setSort("name.first", true);
//
//		list.add(new Contact(new Name("Abby", "Zerind")));
//		list.add(new Contact(new Name("Bernard", "Youst")));
//		list.add(new Contact(new Name("Charlie", "Xerg")));
//		list.add(new Contact(new Name("Deitri", "West")));
//		list.add(new Contact(new Name("Ernie", "Vuntang")));
//		list.add(new Contact(new Name("Frank", "Unter")));
	}

	public Iterator iterator(final int first, final int count) {
		// In this example the whole list gets copied, sorted and sliced; in real applications typically your database would deliver a sorted and limited list 

		// Get the data
		
		return AdminDbOperation.listAllPerson().iterator();
//		return null;
	}

	 

	public int size() {
		return 7;
	}

	@Override
	public IModel model(Object object) {
		return model2(object);
	}

	public IModel model2(final Object object) {
		return new AbstractReadOnlyModel<Object>() {
			@Override
			public Object getObject() {
				return object;
			}
		};
	}

 
	


}

